package com.atguigu.gmall.all.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.item.feign.ItemFeignClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.Map;

/**
 * 商品详情页面渲染
 * 转发视图
 */
@Controller
public class ItemController {


    @Autowired
    private ItemFeignClient itemFeignClient;
    //请求转发到商品详情页面
    @GetMapping("/{skuId}.html")
    public String itemPage(@PathVariable(name = "skuId") Long skuId, Model model){
        Result result = itemFeignClient.getItem(skuId);
        Map<String,Object> data = (Map<String, Object>) result.getData();
        model.addAllAttributes(data);
        return "item/index";
    }
}
